package com.hunan.api.catv.action.attention;

import com.hunan.api.catv.action.BaseAction;
import com.hunan.api.catv.annotation.MemberAuth;
import com.hunan.api.catv.common.Api;
import com.hunan.api.catv.entity.Result;
import com.hunan.api.catv.entity.po.MemberAttentionRecord;
import com.hunan.api.catv.service.biz.attention.AttentionRecordBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: wangchao
 * @Date: 2020/12/1 9:10
 */
@RestController
@Validated
@RequestMapping(Api.attention)
public class AttentionRecordAction extends BaseAction {

    @Autowired
    AttentionRecordBiz attentionRecordBiz;

    /**
     * 获取该用户下的关注列表视频
     */
    @MemberAuth
    @GetMapping("/getAttentionListByMemberId/{pageNum}/{pageSize}")
    public Result getAttentionListByMemberId(HttpServletRequest request, @PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize) {
        return buildOK(attentionRecordBiz.getAttentionListByMemberId(getMemberId(request), pageNum, pageSize), "");
    }

    /**
     * 获取推荐人关注列表
     */
    @MemberAuth
    @GetMapping("/getRecommendAttentionList/{pageNum}/{pageSize}")
    public Result getRecommendAttentionList(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize, HttpServletRequest request) {
        return buildOK(attentionRecordBiz.getRecommendAttentionList(pageNum, pageSize, getMemberId(request)), "");
    }

    /**
     * 判断改用户是否关注人
     */
    @MemberAuth
    @GetMapping("/checkAttention")
    public Result checkAttention(HttpServletRequest request) {
        return buildOK(attentionRecordBiz.checkAttention(getMemberId(request)), "");
    }

    /**
     * 关注/取关
     */
    @MemberAuth
    @PostMapping("/followOrCheckOff")
    public Result followOrCheckOff(HttpServletRequest request, @RequestBody MemberAttentionRecord memberAttentionRecord) {
        return buildOK(attentionRecordBiz.followOrCheckOff(getMemberId(request), memberAttentionRecord), "");
    }

    /**
     * 判断是否关注该用户
     */
    @GetMapping("/checkAttentionByMemberId/{newsId}")
    public Result checkAttentionByMemberId(HttpServletRequest request, @PathVariable("newsId") Integer newsId) {
        return buildResult(attentionRecordBiz.checkAttentionByMemberId(getMemberIdV2(request), newsId));
    }


}
